package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.AppCreateDTO;
import com.winshare.saleAssistant.domain.dto.req.AppMenuUpdateDTO;
import com.winshare.saleAssistant.domain.dto.req.AppUpdateDTO;
import com.winshare.saleAssistant.domain.dto.req.BaseIdDTO;
import com.winshare.saleAssistant.service.AppService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/app")
@CrossOrigin
@Api(value = "应用管理", description = "应用管理")
public class AppController {

    private final AppService appService;

    public AppController(AppService appService) {
        this.appService = appService;
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增应用接口")
    public LogicResponse save(@RequestBody @Validated AppCreateDTO appCreateDTO) {
        appService.saveApp(appCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改应用接口")
    public LogicResponse update(@RequestBody @Validated AppUpdateDTO appUpdateDTO) {
        appService.updateApp(appUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("list")
    @ApiOperation(value = "获取应用列表")
    public LogicResponse getAllAppList() {
        return LogicResponse.success(appService.getAppList());
    }

    @PostMapping("/detail")
    @ApiOperation(value = "获取单个应用详情")
    public LogicResponse getAppDetail(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(appService.getAppDetail(baseIdDTO));
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除某个应用")
    public LogicResponse delete(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        appService.deleteApp(baseIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/add/menuList")
    @ApiOperation(value = "给单个应用添加菜单")
    public LogicResponse addMenu(@RequestBody @Validated AppMenuUpdateDTO appMenuUpdateDTO) {
        appService.addAppMenuList(appMenuUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/menuListByApp")
    @ApiOperation(value = "获取某个应用下的全部菜单(列表形式)",notes = "获取当前用户某个应用下的全部菜单(列表形式)")
    public LogicResponse getMenuListByApp(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(appService.getMenuListByApp(baseIdDTO));
    }

    @PostMapping("/menuListByApp/V2")
    @ApiOperation(value = "获取某个应用下的全部菜单(树状结构)",notes = "获取当前用户某个应用下的全部菜单(树状结构)")
    public LogicResponse getMenuListByAppV2(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(appService.getMenuListByAppV2(baseIdDTO));
    }

}
